Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Dec 5, 2025

Follow up from #6985

#skip-changelog

Closes #6994

@noahsmartin noahsmartin added the ready-to-merge Use this label to trigger all PR workflows label Dec 5, 2025
/// Tracks sessions for release health. For more info see:
/// https://docs.sentry.io/workflow/releases/health/#session
@_spi(Private) @objc(SentrySessionTracker) public final class SessionTracker: NSObject {
final class SessionTracker {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Removing NSObject breaks NotificationCenter selector-based observation

The SessionTracker class no longer inherits from NSObject, but it still uses #selector with NotificationCenter.addObserver(_:selector:name:object:) for lifecycle notifications. Selector-based notification observation requires the observer to inherit from NSObject because the Objective-C runtime needs methods like methodSignatureForSelector: to dispatch the selector. Without NSObject inheritance, the notification callbacks (didBecomeActive, willResignActive, willTerminate) will fail at runtime, breaking session tracking functionality.

Fix in Cursor Fix in Web

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.043%. Comparing base (4ef85d2) to head (9a0b87e).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6993       +/-   ##
=============================================
- Coverage   85.047%   85.043%   -0.004%     
=============================================
  Files          453       453               
  Lines        27640     27640               
  Branches     12135     12132        -3     
=============================================
- Hits         23507     23506        -1     
- Misses        4089      4090        +1     
  Partials        44        44               
Files with missing lines Coverage Δ
...tils/Sources/TestNSNotificationCenterWrapper.swift 100.000% <100.000%> (ø)
...es/Swift/Integrations/Session/SessionTracker.swift 100.000% <100.000%> (ø)
Sources/Swift/SentryDependencyContainer.swift 98.496% <100.000%> (ø)

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ef85d2...9a0b87e. Read the comment docs.

Copy link
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please double-check if the cursor feedback for select-based observation is valid.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1238.53 ms 1264.46 ms 25.93 ms
Size 24.14 KiB 1.02 MiB 1018.11 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
5c2d5d6 1225.39 ms 1259.45 ms 34.06 ms
3b059e5 1201.31 ms 1229.61 ms 28.30 ms
d1c4916 1236.25 ms 1266.76 ms 30.51 ms
e70670c 1223.47 ms 1238.67 ms 15.20 ms
99ec589 1209.73 ms 1231.98 ms 22.24 ms
458a7d6 1212.67 ms 1244.90 ms 32.23 ms
1a34ddc 1218.94 ms 1251.86 ms 32.92 ms
605fa27 1226.31 ms 1251.35 ms 25.05 ms
1ed7bf6 1215.78 ms 1255.78 ms 40.00 ms
f8687d1 1227.54 ms 1258.44 ms 30.90 ms

App size

Revision Plain With Sentry Diff
5c2d5d6 23.75 KiB 969.28 KiB 945.54 KiB
3b059e5 23.75 KiB 980.73 KiB 956.99 KiB
d1c4916 23.75 KiB 981.15 KiB 957.40 KiB
e70670c 23.75 KiB 975.19 KiB 951.45 KiB
99ec589 23.75 KiB 983.31 KiB 959.57 KiB
458a7d6 23.75 KiB 1.01 MiB 1016.13 KiB
1a34ddc 23.75 KiB 919.88 KiB 896.13 KiB
605fa27 23.75 KiB 908.03 KiB 884.28 KiB
1ed7bf6 24.14 KiB 1.01 MiB 1012.91 KiB
f8687d1 23.75 KiB 988.01 KiB 964.27 KiB

Previous results on branch: removeSomeObjC

Startup times

Revision Plain With Sentry Diff
111ea8f 1216.60 ms 1258.74 ms 42.14 ms
439f29d 1210.96 ms 1244.69 ms 33.73 ms

App size

Revision Plain With Sentry Diff
111ea8f 24.14 KiB 1.02 MiB 1018.10 KiB
439f29d 24.14 KiB 1.02 MiB 1018.11 KiB

@objcMembers public class TestNSNotificationCenterWrapper: NSObject {
private enum Observer {
case observerWithObject(WeakReference<NSObject>, Selector, NSNotification.Name?, Any?)
case observerWithObject(WeakReference<AnyObject>, Selector, NSNotification.Name?, Any?)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Observer removal fails for non-NSObject observers in test utility

The Observer.observerWithObject case was changed to use WeakReference<AnyObject> to support non-NSObject observers, but the removeObserver method's comparison logic at line 85 still uses observer as? NSObject. For non-NSObject observers, this cast returns nil, causing the identity comparison weakObserver.value === observer as? NSObject to fail, so observers won't be properly removed. The comparison should use observer as AnyObject instead.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Remove extra @objc from SessionTracker

3 participants